package com.zfzs.post.modules.backstage.service.impl;

import com.zfzs.post.modules.backstage.domain.UserInfo;
import com.zfzs.post.modules.backstage.repository.BackStageUserRepository;
import com.zfzs.post.modules.backstage.service.BackStageUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* @author ck
* @date 2019-08-07
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class BackStageUserServiceImpl implements BackStageUserService {

    @Autowired
    private BackStageUserRepository backStageUserRepository;

    @Override
    public UserInfo findById(Long channelId) {
        Optional<UserInfo> byId = backStageUserRepository.findById(channelId);
        return byId.isPresent()?byId.get():null;
    }

    @Override
    public List<Long> findAllChannelId() {
        return backStageUserRepository.findAll().stream().map(UserInfo::getId).collect(Collectors.toList());
    }
}